/**
 * 数组中找到key为value的首个符合要求的对象的下标，无则返回-1
 * @param {String} key
 * @param {Object} value
 * @param {Array} arr
 * @returns {int}
 */
function arrIndexOfKeyVal(key,value, arr) {
    if(key && value && arr) {
        for(var o in arr) {
            if(arr[o][key] === value) return Number(o);
        }
    }
    return -1;
}

// var obj1 = {"name":"user1", "old":1};
// var obj2 = {"old":2, "name":"user2"};
// var obj3 = {"old":3};
// var obj4 = {"name":"user4"};
// var arr = [obj1, obj2, obj3, obj4];
// console.log(arrIndexOfKeyVal('old',1,arr))

module.exports = arrIndexOfKeyVal